import type { App, Component } from "vue";

import TabsHead from "./TabsHead.vue";
import TabsBottom from "./TabsBottom.vue";
import TabItem from "./TabItem.vue";

const components: Component[] = [TabsHead, TabsBottom, TabItem];

// 定义「全局注册组件」回调函数，接收 Vue 实例作为参数，外部应用在执行 `app.use(当前插件库)` 时调用
const install = (app: App): void => {
  components.forEach((component: Component) => {
    console.log('component: ', component);
    if (component.name) {
      app.component(component.name, component);
    } else {
      throw new Error(`Component has no name: ${component}`);
    }
  });
};

// 默认导出 install，以供外部应用「全局注册」当前插件库
export default { install };

// 命名导出，以供外部应用「按需导入」当前插件库的组件
export { TabsHead, TabsBottom, TabItem };
